#include <bits/stdc++.h>
using namespace std;
const int maxn = 20+2;
int G[maxn][maxn], d[maxn], l[maxn], nex[maxn];
int N;
int DP(int i){
    if(d[i] > -1) return d[i];
    d[i] = l[i];
    for (int j = 1; j <= N; ++j) {
        int t = l[i]+DP(j);
        if(G[i][j] && t > d[i]) d[i] = t, nex[i] = j;
    }
    return d[i];
}
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> N;
    memset(d, -1, sizeof(d));
    for (int i = 1; i <= N; ++i) {
        cin >> l[i];
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = i+1; j <= N; ++j) {
            cin >> G[i][j];
        }
    }

    int ans = 0, s = 0;
    for (int i = 1; i <= N; ++i) {
        if(DP(i) > ans) ans = DP(i), s = i;
    }
    bool fir = true;
    while (s){
        if(!fir) cout << " ";
        if(fir) fir = false;
        cout << s;
        s = nex[s];
    }

    cout << "\n" << ans;
    return 0;
}